﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>转工数据查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'转工数据查询报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :rules="rules" style="margin: 10px"
        :label-position="'left'">

        <el-form-item label="主制分厂:" prop="factoryid">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择主制分厂" clearable filterable @change="bindControl">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="主制工区:">
          <el-select v-model="queryInfo.workcenterid" placeholder="请选择主制工区" clearable filterable>
            <el-option v-for="w in workcenterList" :key="w.workcenterid" :label="w.workcentername"
              :value="w.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="机型:">
          <el-select v-model="queryInfo.productfamilyname" placeholder="请选择机型" clearable filterable>
            <el-option v-for="i in productFamilyList" :key="i.productfamilyname" :label="i.productfamilyname"
              :value="i.productfamilyname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="转出时间:">
          <el-date-picker v-model="queryInfo.createDate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="转出人:">
          <el-select v-model="queryInfo.workerid" placeholder="请选择" clearable filterable style="width:100px;">
            <el-option v-for="w in factoryDiaoDuYuanList" :key="w.employeeid" :label="w.fullname" :value="w.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="转工状态:">
          <el-select v-model="queryInfo.status" placeholder="请选择" clearable filterable style="width:100px;">
            <el-option :key="'未转出'" :label="'未转出'" :value="'未转出'"></el-option>
            <el-option :key="'已转出'" :label="'已转出'" :value="'已转出'"></el-option>
            <el-option :key="'已接收'" :label="'已接收'" :value="'已接收'"></el-option>
            <el-option :key="'已完成'" :label="'已完成'" :value="'已完成'"></el-option>
            <el-option :key="'已转入'" :label="'已转入'" :value="'已转入'"></el-option>
            <el-option :key="'已拒收'" :label="'已拒收'" :value="'已拒收'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-popover placement="top-start" title="统计说明" width="300" trigger="hover" content="">
            <el-tag class="el-icon-info" slot="reference"> 统计说明</el-tag>
            <p>该报表不统计【已入库】批次的转工记录</p>
          </el-popover>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" element-loading-text="数据加载中"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border show-overflow-tooltip>
        <el-table-column type="index" width="40px"></el-table-column>
        <el-table-column prop="factoryname" label="发出分厂" width="140px"></el-table-column>
        <el-table-column prop="fromworkcentername" label="工区" width="140px"></el-table-column>
        <el-table-column prop="familylistnames" label="机型" width="120px" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productname" label="零件图号" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productdescription" label="零件名称" width="140px" show-overflow-tooltip></el-table-column>
        <el-table-column prop="containername" label="流水卡号"></el-table-column>
        <el-table-column prop="outspecname" label="转工工序"></el-table-column>
        <el-table-column prop="workflowinfo" label="转工工序工艺" width="160" show-overflow-tooltip></el-table-column>
        <el-table-column prop="qty" label="在制数" width="60"></el-table-column>
        <el-table-column prop="tofactoryname" label="承制分厂" width="120px"></el-table-column>
        <el-table-column prop="reqemployee" label="申请人" width="100px" v-if="false"></el-table-column>></el-table-column>
        <el-table-column prop="status" label="转工状态" width="80px">
          <template scope="scope">
            <div v-if="scope.row.status">
              <el-tag v-if="scope.row.status === '已拒收'" type="danger">{{scope.row.status}}</el-tag>
              <el-tag v-else-if="scope.row.status === '已转入'" type="success">{{scope.row.status}}</el-tag>
              <el-tag v-else>{{scope.row.status}}</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="转工详细信息" width="140px" type="expand" style="background-color: red;">
          <template scope="scope">
            <el-row :gutter="20">
              <el-col :span="6">
                <el-card>
                  <div slot="header"><span>转出分厂转工详细信息</span></div>
                  <div v-if="scope.row.senderimages">
                    <el-image style="width:48px;height: 48px;" :src="scope.row.senderimages"
                      :preview-src-list="[scope.row.senderimages]">
                    </el-image>
                  </div>
                  <div v-else>
                    <el-image style="width:48px;height: 48px;" :src="'../images/person_blue.png'"></el-image>
                  </div>
                  <p>转出人: {{scope.row.submitemployee}}</p>
                  <p>转出时间: {{scope.row.submitdate && scope.row.submitdate.replace('T',' ')}}</p>
                  <p>主制工区: {{scope.row.fromworkcentername}}</p>
                  <p>转出工序: {{scope.row.outspecname}}</p>
                  <p>要求完成时间: {{ scope.row.needcompletedate && scope.row.needcompletedate.split('T')[0]}}</p>
                  <p>转入人: {{ scope.row.returnemployee }}</p>
                  <p>转入工序: {{ scope.row.inspecname }}</p>
                  <p>转入时间: {{ scope.row.returndate && scope.row.returndate.replace('T',' ')}}</p>
                </el-card>
              </el-col>
              <el-col :span="6">
                <el-card>
                  <div slot="header"><span>承制分厂转工详细信息</span></div>
                  <div v-if="scope.row.receiverimages">
                    <el-image style="width:48px;height: 48px;" :src="scope.row.receiverimages"
                      :preview-src-list="[scope.row.receiverimages]">
                    </el-image>
                  </div>
                  <div v-else>
                    <el-image style="width:48px;height: 48px;" :src="'../images/person_blue.png'"></el-image>
                  </div>
                  <p>接收人: {{scope.row.toacceptor}}</p>
                  <p>接收时间: {{ scope.row.acceptdate && scope.row.acceptdate.replace('T',' ')}}</p>
                  <p>承制工区: {{scope.row.toworkcentername}}</p>
                  <p>预计完成时间: {{ scope.row.estimatedcompletedate && scope.row.estimatedcompletedate.split('T')[0]}}</p>
                  <p>实际完成时间: {{ scope.row.completedate && scope.row.completedate.replace('T',' ')}}</p>
                  <p style="color:red;">拒收人: {{scope.row.denyperson}}</p>
                  <p style="color:red;">拒收时间: {{ scope.row.denydate && scope.row.denydate.replace('T',' ')}}</p>
                  <p style="color:red;">拒收原因: {{scope.row.reasonnote}}</p>
                </el-card>
              </el-col>
            </el-row>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[11,20,50]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getProductFamily, getFactory, getFactoryUsersByRoleName, getWorkcenterList, getUserInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        loading: false,
        total: 0,
        queryInfo: {
          factoryid: '',//主制分厂
          workcenterid: '',// 主制工区
          workerid: '',// 转出人
          productfamilyname: '',// 机型
          mfgordername: '',// 订单号
          productname: '',// 零件图号
          containername: '',// 流水卡号
          createDate: '',// 报废时间
          currentPage: 1,//当前页
          pageSize: 11//每页显示条数
        },
        dataList: [],
        factoryList: [],
        workcenterList: [],
        productFamilyList: [],
        factoryDiaoDuYuanList: [],
        // 表单验证
        rules: { factoryid: [{ required: true, message: '主制分厂不能为空', trigger: 'change' }] },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback });
        },
        async bindControl(factoryid) {
          this.queryInfo.workcenterid = null;
          this.queryInfo.workerid = null;
          if (factoryid) {
            this.workcenterList = await getWorkcenterList({ factoryid });
            this.factoryDiaoDuYuanList = await getFactoryUsersByRoleName({ factoryid, rolename: '调度员' });
          }
        },
        // 查询数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios.post('../handler/report/ContainerShipRecordReport.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
            }
          })
        },
        //导出excel
        async getExportExcel() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              const config = {
                url: '../handler/report/ContainerShipRecordReport.ashx?action=exportExcel',
                data: { type: 'exportExcel', ...this.queryInfo }
              }
              exportExcelData(config, this);
            }
          })
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        this.productFamilyList = await getProductFamily();
        this.factoryList = await getFactory();
        const userInfo = await getUserInfo({ employeeid: getParams("uid") });
        const { factoryid } = this.factoryList.some(i => i.factoryid === userInfo.factoryid) ? userInfo : this.factoryList[0];
        this.queryInfo.factoryid = factoryid;
        this.workcenterList = await getWorkcenterList({ factoryid });
        this.factoryDiaoDuYuanList = await getFactoryUsersByRoleName({ factoryid, rolename: '调度员' });
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>